"""
用户中心的订单相关page
"""
# 导入base模块
from common.base import Base, By


# TODO 定义用户中心类，继承Base类
class UserCenterPage(Base):

    # 定位用户中心,点击进入
    def user_center(self):
        self.click((By.LINK_TEXT, '用户中心'))

    # 定位我的订单,点击进入
    def my_order(self):
        self.click((By.XPATH, '/html/body/div[6]/div[1]/div/div/div/div/a[3]'))

    # 返回最新一条订单的编号
    def read_order_id(self):
        return self.get_element_text((By.XPATH, '/html/body/div[6]/div[2]/div/div/div/table/tbody/tr[1]/td[1]/a'))


if __name__ == '__main__':
    from common.functions import browser_operation

    driver = browser_operation()
    driver.implicitly_wait(5)
    driver.get('http://172.16.140.55/ecshop/user.php')
    driver.find_element(By.NAME, 'username').send_keys('zhang')
    driver.find_element(By.NAME, 'password').send_keys('123456')
    driver.find_element(By.NAME, 'submit').click()
    read = UserCenterPage(driver)
    read.user_center()
    read.my_order()
    read.read_order_id()
